<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px" size="mini">
      <el-form-item label="用户名">
        <el-input v-model="form.nickname" ></el-input>
      </el-form-item>
	  <el-form-item label="真实姓名">
	    <el-input v-model="form.username" ></el-input>
	  </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="form.password" show-password></el-input>
      </el-form-item>

      <el-form-item label="邮箱">
        <el-input v-model="form.email" ></el-input>
      </el-form-item>
	  <el-form-item label="电话号">
	    <el-input v-model="form.telephone" ></el-input>
	  </el-form-item>

      <el-form-item>
        <el-button type="primary" plain @click="save">保存数据</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
		import axios from '../../utils/axiosutils.js'
  export default {
    name: 'RoleEdit',
    props: ['editid'],
    data() {
      return {
        form: {
			id:'',
			nickname:'',
			password:'',
          username: '',
		  email:'',
		  telephone:''
        }
      }
    },
	created() {
		if (this.editid) {
			axios.get(
				'/user/getById',
				response => {
					console.log(this.editid);
					this.form.id=response.obj.id;
					this.form.nickname = response.obj.nickname;
					this.form.username = response.obj.username;
					this.form.email = response.obj.email;
					this.form.telephone = response.obj.telephone;
					this.form.password = response.obj.password;
					
				}, {
					id: this.editid
				}
			);
		}
	},
	methods: {
		save: function() {
			axios.post(
				'/user/add',
				resp => {
					this.$emit('update:show', false);
					this.$emit('getData');
				},
				this.form
			);
		}
	}
  }
</script>

<style>
</style>
